#!/bin/bash

echo "----------------配置ssh-------------------------"
sudo apt install -y git wget dos2unix
if [ ! -d "$HOME/.ssh" ]; then
    mkdir $HOME/.ssh
fi
wget https://gitee.com/kduant/vimrc/raw/master/.ssh/id_rsa -P $HOME/.ssh
wget https://gitee.com/kduant/vimrc/raw/master/.ssh/id_rsa.pub -P $HOME/.ssh
chmod 600 $HOME/.ssh/id_rsa
chmod 600 $HOME/.ssh/id_rsa.pub

# git配置
echo "--------------------配置git选项-----------------------"
git config --global user.email "wangjun850725@163.com"
git config --global user.name "kdurant"
git config --global core.autocrlf input
git config --global core.editor nvim
git config --global http.sslVerify "false"
git config --global http.postBuffer 1048576000

git config --global alias.st "status"
git config --global alias.br "branch"
git config --global alias.lo "log --graph --pretty=oneline"
git config --global alias.cm "commit -m"
git config --global alias.co "checkout"

git config --global --add safe.directory "*"



sed '/HISTSIZE/s/\<1000\>/-1/' -i ~/.bashrc
sed '/HISTFILESIZE/s/\<2000\>/-1/' -i ~/.bashrc


sudo apt install -y build-essential xclip net-tools cmake
sudo apt install -y wget dos2unix neofetch bat curl ripgrep git gitk git-lfs bear fd-find jq exa duf
sudo apt install -y nfs-common openssh-server openssh-client


if [ -z `which rustc` ]; then 
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    rustup update

    sudo apt install -y cargo
    echo '[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "ustc" 
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
    ' > ~/.cargo/config

    # atuin
    cargo install atuin
    cargo install eza
    cargo install du-dust
    cargo install tree-sitter-cli
    # cargo install teehee
    # cargo install --locked tealdeer
    # cargo install --locked watchexec-cli
    cargo install --locked zoxide
    sed -i '$a eval "$(zoxide init bash)"' ~/.bashrc
fi

if [ -z `which node` ]; then 
    wget -P ~/Downloads https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.xz
    tar -vxf ~/Downloads/node-v20.9.0-linux-x64.tar.xz -C ~/Downloads
    sudo mv ~/Downloads/node-v20.9.0-linux-x64 /opt/node

    # /etc/profile后追加以下环境变量
    sudo sed '$a NODE_HOME=/opt/node' -i /etc/profile
    sudo sed '$a PATH=$PATH:$NODE_HOME/bin' -i /etc/profile
    sudo sed '$a NODE_PATH=$NODE_HOME/lib/node_mudules' -i /etc/profile
    source /etc/profile
    
    sudo ln -s /opt/node/bin/node /usr/local/bin/node
    sudo ln -s /opt/node/bin/npm /usr/local/bin/npm
    
    npm config set registry http://registry.npm.taobao.org/
    if [ -z `which yarn` ]; then
        curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
        echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
        sudo apt update
        sudo apt install -y yarn
    fi
    yarn config set registry https://registry.npm.taobao.org -g
    yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
fi

if [ -z `which lua` ]; then 
    sudo apt install -y lua5.1 luarocks
    sudo apt install -y sqlite3 libsqlite3-dev sqlitebrowser
    sudo luarocks install luv
    sudo luarocks install sqlite3
fi

if [ -z `which nvim` ]; then  
    sudo add-apt-repository -y ppa:neovim-ppa/unstable
    sudo apt update
    sudo apt install -y neovim

    yarn global add neovim
    sudo npm install -g neovim
    sudo npm install -g tree-sitter

    git clone --filter=blob:none --single-branch git@github.com:folke/lazy.nvim.git ~/.local/share/nvim/lazy
    ln -s $HOME/vimrc/.config/nvim/ $HOME/.config/nvim
fi

git clone --depth 1 git@github.com:junegunn/fzf.git ~/.fzf
~/.fzf/install
